package com.luoxiang.socialandroid.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.CircleCrop;
import com.bumptech.glide.request.RequestOptions;
import com.luoxiang.socialandroid.R;
import com.luoxiang.socialandroid.app.MyAppliaction;
import com.luoxiang.socialandroid.bean.Award;

import java.util.List;

public class InviteawardAdapter extends RecyclerView.Adapter<InviteawardAdapter.ViewHolder> {
    private List<Award> list;

    public InviteawardAdapter(List<Award> list) {
        this.list = list;
    }

    private String url = "https://dahuixiong.oss-cn-shenzhen.aliyuncs.com/";

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.item_inviteuser, parent, false);
        InviteawardAdapter.ViewHolder holder = new InviteawardAdapter.ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        Award bean = list.get(position);
        Glide.with(MyAppliaction.getContext())
                .load(url + bean.getIcon())
                .apply(RequestOptions.bitmapTransform(new CircleCrop()))
                .into(holder.im_icon);
        holder.tx_name.setText(bean.getName());
        holder.tx_date.setText(bean.getCreateTime());
        holder.tx_credit.setText(holder.tx_credit.getContext().getString(R.string.mi_huode) + bean.getCredit() + holder.tx_credit.getContext().getString(R.string.mi_jifen));
    }

    @Override
    public int getItemCount() {
        try {
            return list.size();
        } catch (Exception e) {
            return 0;
        }
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        private ImageView im_icon;
        private TextView tx_name, tx_date, tx_credit;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            im_icon = itemView.findViewById(R.id.im_icon);
            tx_name = itemView.findViewById(R.id.tx_name);
            tx_date = itemView.findViewById(R.id.tx_date);
            tx_credit = itemView.findViewById(R.id.tx_credit);
        }
    }
}
